package com.leo.app;

import javafx.application.Application;
import javafx.stage.Stage;

/**
 * @ClassName Game
 * @Description 启动类，需要继承 程序入口
 * @Author wangss
 * @date 2020.12.07 19:47
 * @Version 1.0
 */
public abstract class Game extends Application {

    private UIApp uiApp;

    @Override
    public final void start(Stage primaryStage) throws Exception {
        uiApp = new UIApp(primaryStage);
        uiApp.onLaunch = this::onLaunch;
        uiApp.onFinish = this::onFinish;
        uiApp.onExit = this::onExit;
        uiApp.launch();
    }

    @Override
    public final void stop() throws Exception {
        uiApp.finish();
    }

    /**
     * 加载
     */
    public abstract void onLaunch();

    /**
     * 加载完成
     */
    public abstract void onFinish();

    /**
     * 退出
     *
     * @return
     */
    public boolean onExit() {
        return true;
    }
}
